package com.mybatisplus.demo.android.controller;

import com.mybatisplus.demo.android.enmu.ApiResponse;
import com.mybatisplus.demo.android.error.BusinessException;
import com.mybatisplus.demo.android.rep.RegisterRep;
import com.mybatisplus.demo.android.service.RegisterService;
import com.mybatisplus.demo.android.util.ApiResponseUtil;
import io.swagger.annotations.*;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.validation.Valid;

/**
 * 用户类
 */
@Api(value = "注册", description = "注册接口", tags = "注册模块", position = 1)
@Controller
public class RegisterController extends BaseContriller {

    @Autowired
    private RegisterService registerService;

    @PostMapping("/user/register")
    @ResponseBody
    @ApiOperation(value = "根据手机号和密码、验证码注册", notes = "注册请求接口", httpMethod = "POST", response = ApiResponse.class)
    @ApiResponses(value = {
            @io.swagger.annotations.ApiResponse(code = 200, message = "{\"code\":200,\"message\":\"success\",\"data\":null}"),
            @io.swagger.annotations.ApiResponse(code = 207, message = "{\"code\":207,\"message\":\"用户不能为空\",\"data\":null}"),
            @io.swagger.annotations.ApiResponse(code = 208, message = "{\"code\":208,\"message\":\"密码不能为空\",\"data\":null}")
    })
    public ApiResponse Register(@Valid @RequestBody RegisterRep registerRep) throws BusinessException {

//        if (StringUtils.isEmpty(user_id)) {
//            throw new BusinessException(ResultCode.VERIFY_NAME_NULL);
//        }
//        if (StringUtils.isEmpty(password)) {
//            throw new BusinessException(ResultCode.VERIFY_PASSWORD_NULL);
//        }
        ApiResponse lc = registerService.register(registerRep.getUser_id(), registerRep.getPassword(), registerRep.getCode());
        System.out.println("注册反馈： " + lc.toString());
        return ApiResponseUtil.getResult(lc);
    }

}
